#include <ime.h>
#include <stdio.h>
#include <string.h>
typedef struct _TrieNode{
	struct _TrieNode* ch[26];
	int ispy;
} TrieNode;
typedef struct {
	char chn[100];
	int  nchn;
	int  begin;
} PYData;
TrieNode pydict;
char  wordlist[70000][20];
int pylist[70000][10];
float  feq[70000];
int nword;
void trie_insert(const char* str, int n,TrieNode* t)
{
	for(; *str; t = t->ch[(*(str++))-'a'])
	{
		if(NULL == t->ch[(*str)-'a'])
		{
			TrieNode* node = t->ch[(*str)-'a'] = (TrieNode*)malloc(sizeof(TrieNode));
			memset(node, 0 , sizeof(TrieNode));
		}
	}
	t->ispy = n;
}
int init(char* param,void* ic)
{
	FILE* fin = fopen(param, "r");
	if(NULL == fin) return -1;
	int N, i;
	fscanf(fin,"%d",&N);
	memset(&pydict, 0, sizeof(pydict));
	for(i = 0; i < N; i ++)
	{
		int n;
		char buf[10];
		fscanf(fin,"%d %s",&n,buf);
		trie_insert(buf, n ,&pydict);
	}
	fscanf(fin,"%d",&nword);
	for(i = 0; i < nword; i ++)
	{
		fscanf(fin,"%d",&pylist[i][0]);
		int j;
		for(j = 0; j < pylist[i][0]; j ++)
			fscanf(fin,"%d",&pylist[i][1+j]);
		fscanf(fin,"%f", &feq[i]);
		fscanf(fin,"%s", wordlist[i]);
	}
	return 0;
}
int onselect(uint32_t sym, uint32_t state, uint32_t id,void* ic)
{
	return 0;
}
int enabled(void* ic)
{
	PYData* IC = (PYData*)ic;
	IC->begin = IC->nchn = 0;
	IMRegisterForwardFilter('0','9'+1,IMStateAll,IMStateNone,IMKeyActionPress, onselect, ic);
	return 0;
}
MetaDataBegin(Pinyin, PYData, 1)
	IMSetMetaData(NCandidates,10); //1234567890
	IMRegisterEventHandler(OnInitialize, init);
	IMRegisterEventHandler(OnEnabled, enabled);
MetaDataEnd


